<?php
/**
 * 员工管理
*/
apf_require_class("Bll_BLL");
class Bll_Flow_UserSame extends BLL{
    /**
     * 获取同名编号
     */
    public function get_user_same_num(){
        $now_year = intval(date('Y'));
        $result = $this->_get_yesr_to_word($now_year);
        $user_same = $this->get_user_same_dao()->find_by_id($now_year);

        if($user_same){
            $num = $user_same['num']+1;
            $result .= $num;
            $this->get_user_same_dao()->update_by_id($now_year, array('num'=>$num));
        }else{
            $result .= "1";
            $this->get_user_same_dao()->insert(array('year'=>$now_year,'num'=>1));
        }
        return strtolower($result);
    }
    /**
     * “A”代表2007年，“B”代表2008年，以此类推
     * 超过‘Z’对应的年份之后，没做处理
     */
    private function _get_yesr_to_word($now_year){
        $base_year = 2007;
        $i = $now_year - $base_year;
        $words = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','Q','R','T','U','V','W','X','Y','Z');
        return $words[$i];
    }
    /**
     *
     * @return Dao_Flow_UserSame
     */
    private function get_user_same_dao(){
        $dao = $this->get_dao('Dao_Flow_UserSame');
        return $dao;
    }
    private static $bll_same;
    /**
     * @return Bll_Flow_UserSame
     */
    public static function get_instance(){
        if(!self::$bll_same){
            self::$bll_same = new Bll_Flow_UserSame();
        }
        return self::$bll_same;
    }
}
